<?php 
require("admin-header.php");
require_once("../maincore.php");
if (!defined("THNOJ")) die ("Outside of the site");


$sql="SELECT max(`problem_id`) as upid FROM `problem`";
$page_cnt=50;
$result=mysql_query($sql);

$row=mysql_fetch_object($result);
$cnt=intval($row->upid)-1000;
$cnt=intval($cnt/$page_cnt)+(($cnt%$page_cnt)>0?1:0);
if (isset($_GET['page'])){
	$page=intval($_GET['page']);
}else $page=$cnt;
$pstart=1000+$page_cnt*intval($page-1);
$pend=$pstart+$page_cnt;

echo "<title>Danh sách đề bài</title>";
echo "<center><h2>Danh sách đề bài</h2></center>Trang ";

for ($i=1;$i<=$cnt;$i++){
	if ($i>1) echo '&nbsp;';
	if ($i==$page) echo "<span class=red>$i</span>";
	else echo "<a href='problem_list.php?page=".$i."'>".$i."</a>";
}

$sql="select * FROM `problem` where problem_id>=$pstart and problem_id<=$pend and author_id='$myid' order by `problem_id` desc";
//echo $sql;
$result=mysql_query($sql) or die(mysql_error());
echo "<center><table width=90% border=1>";
echo "<form method=post action=contest_add.php>";
echo "<tr><td colspan=5><input type=submit name='problem2contest' value='Nhập vào kì thi mới'>";
echo "<tr><td>Mã số<td>Tiêu đề<td>Ngày";
if(isset($_SESSION['user_rights'])){
	echo "<td>Trạng thái<td>Lựa chọn</tr>";
}
for (;$row=mysql_fetch_object($result);){
	echo "<tr>";
	echo "<td>".$row->problem_id;
	echo "<input type=checkbox name='pid[]' value='$row->problem_id'>";
	echo "<td><a href='../exercise.php?id=$row->problem_id'>".$row->title."</a>";
	echo "<td>".$row->in_date;
	if(isset($_SESSION['user_rights'])){
		echo "<td>"
		.($row->defunct=="N"?"<span class=green>Sử dụng</span>":"<span class=red>Dự trữ</span>")." <a href=problem_df_change.php?id=$row->problem_id><img src='../image/toggle.png' alt='[Đổi]' title='Hoán đổi'/></a>";
		echo "<td>[<a href=problem_edit.php?id=$row->problem_id>Sửa</a>][<a href=problem_tests.php?pid=$row->problem_id>Test</a>] [<a href=status.php?pid=$row->problem_id>Kết quả</a>]";
	}
	echo "</tr>";
}
echo "<tr><td colspan=5><input type=submit name='problem2contest' value='Nhập vào kì thi mới'>";
echo "</tr></form>";
echo "</table><br/><a href='problem_add_page.php'>Thêm bài toán mới</a></center>";
require("../oj-footer.php");
?>
